package com.ecoolex.discount.sales.job.scheduler;

import com.ecoolex.discount.sales.core.manager.DiscountOrderManager;
import com.ecoolex.discount.sales.entity.DiscountOrder;
import com.ecoolex.framework.scheduler.Job;
import com.ecoolex.framework.scheduler.JobComponent;

import java.util.Calendar;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

@JobComponent
public class DiscountOrderCheckJob {
    @Autowired
    private DiscountOrderManager discountOrderManager;

    @Job(name = "discount.sales.DiscountOrderCheckJob.autoCancel", describe = "自动取消未支付订单")
    public void autoCancel() {
        discountOrderManager.queryOverduePay(10, 10)
                .forEach(order -> discountOrderManager.autoCancel(order, this.getClass().getSimpleName()));
    }
    
    @Job(name = "discount.sales.DiscountOrderCheckJob.expire", describe = "处理产品过期的订单")
    public void expire() {
    	Calendar calendar = Calendar.getInstance();
    	List<DiscountOrder> list = discountOrderManager.queryExpireOrder(calendar.getTime(), 10);
    	
    	list.forEach(discountOrder -> {
    		discountOrderManager.updateToExpiredStatus(discountOrder, DiscountOrderCheckJob.class.getSimpleName());
    	});
    }
    
}
